<style type="text/css">
    .center{text-align:center}
</style>
<body>
<div class="bjy-admin-nav">
	<a href="<{:url('index/welcome')}>"><i class="fa fa-home"></i> 首页</a>&gt;用户组管理
</div>
<ul id="myTab" class="nav nav-tabs">
   	<li class="active">
		<a href="#home" data-toggle="tab">用户组列表</a>
   	</li>
   	<li>
		<a href="javascript:;" onclick="add()">添加用户组</a>
	</li>
</ul>
<div id="myTabContent" class="tab-content">
   <div class="tab-pane fade in active" id="home">
		<table class="table table-striped table-bordered table-hover table-condensed">
			<tr>
				<th class="center">用户组名</th>
				<th>操作</th>
			</tr>
			<{volist name="list" id="vo"}>
				<tr>
					<td class="center" style="width:400px;"><{$vo.title}></td>
					<td>
						<a href="javascript:;" ruleId="<{$vo.id}>" ruleTitle="<{$vo.title}>" onclick="edit(this)">修改</a> |
						<a href="javascript:void(0);" class="delete" data-id="<{$vo.id}>">删除</a> |
						<a href="<{:url('rule_group',['group_id'=>$vo.id])}>">分配权限</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					</td>
				</tr>
			<{/volist}>
		</table>
   </div>
</div>

<!-- 添加菜单模态框开始 -->
<div class="modal fade" id="bjy-add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		 <div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title" id="myModalLabel">
					添加用户组
				</h4>
			</div>
			<div class="modal-body">
				<form id="bjy-form" class="form-inline">
					<table class="table table-striped table-bordered table-hover table-condensed">
						<tr>
							<th width="15%">用户组名：</th>
							<td>
								<input class="form-control" type="text" name="title">
							</td>
						</tr>
						<tr>
							<th></th>
							<td>
								<input class="btn btn-success group" type="button" value="添加">
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</div>
</div>
<!-- 添加菜单模态框结束 -->

<!-- 修改菜单模态框开始 -->
<div class="modal fade" id="bjy-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		 <div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title" id="myModalLabel">
					修改规则
				</h4>
			</div>
			<div class="modal-body">
				<form id="bjy-form" class="form-inline">
					<input type="hidden" name="id">
					<table class="table table-striped table-bordered table-hover table-condensed">
						<tr>
							<th width="12%">规则名：</th>
							<td>
								<input class="form-control" type="text" name="titles">
							</td>
						</tr>
						<tr>
							<th></th>
							<td>
								<input class="btn btn-success submit-save" type="button" value="修改">
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</div>
</div>
<!-- 修改菜单模态框结束 -->

<script type="text/javascript">
// 添加菜单
function add(){
	$("input[name='title']").val(null);
	$('#bjy-add').modal('show');
}

// 修改菜单
function edit(obj){
	$("input[name='id']").val($(obj).attr('ruleId'));
	$("input[name='titles']").val($(obj).attr('ruletitle'));
	$('#bjy-edit').modal('show');
}


$(function(){
	/*	用户组删除
	 */
    $('.delete').click(function(){
        if(window.confirm("您确定要删除吗？")){
            thi = $(this);
            $.post("<{:url('group_delete')}>",{'id':$(this).data('id')},function(data){
                if(data.code){
                    alert('删除成功');
                    $(thi).parents('tr').remove();
                }else{
                    alert(data.msg);
                }
            },'json');
        }
    })
    /*	用户组添加
	 */
    $('.group').click(function(){
        var title = $("input[name='title']").val();
        if(title == ''){
        	alert('请填写用户组名！');
        	return false;
        }

        $.post("<{:url('group_insert')}>",{'title':title},function(data){
            if(data.code){
                alert(data.msg);
                window.location.href="<{:url('group')}>";
            }else{
                alert(data.msg);
            }
        },'json');
    })
    /*	用户组修改
	 */
    $('.submit-save').click(function(){
        var title = $("input[name='titles']").val();
        var id = $("input[name='id']").val();
        if(title == ''){
        	alert('请填写用户组名！');
        	return false;
        }
        $.post("<{:url('group_update')}>",{'title':title,'id':id},function(data){
            if(data.code){
                alert(data.msg);
                window.location.href="<{:url('group')}>";
            }else{
                alert(data.msg);
            }
        },'json');
    })
})

</script>
</body>